#pragma once
#include "RBTree.hpp"
namespace lw
{
	template<class K, class V, class Compare = std::less<K>>
	class map
	{
		struct MapKofT
		{
			const K& operator()(const std::pair<const K, V>& kv) const
			{ 
				return kv.first;
			}
		};
	public:
		typedef lw::RBTree<K, std::pair<const K, V>, MapKofT, Compare>::iterator iterator;
		typedef lw::RBTree<K, std::pair<const K, V>, MapKofT, Compare>::const_iterator const_iterator;
		iterator begin()
		{
			return _t.begin();
		}
		const_iterator begin() const
		{
			return _t.begin();
		}
		iterator end()
		{
			return _t.end();
		}
		const_iterator end() const
		{
			return _t.end();
		}
		size_t size() const
		{
			return _t.size();
		}
		bool empty() const
		{
			return _t.empty();
		}
		void clear()
		{
			_t.clear();
		}
		iterator find(const K& key)
		{
			return _t.Find(key);
		}
		const_iterator find(const K& key) const
		{
			return _t.Find(key);
		}
		std::pair<iterator, bool> insert(const std::pair<const K, V>& kv)
		{
			return _t.Insert(kv);
		}
		V& operator[](const K& key)
		{
			std::pair<iterator, bool> p = insert(std::make_pair(key, V()));
			return p.first->second;
		}
	private:
		lw::RBTree<K, std::pair<const K, V>, MapKofT, Compare> _t;
	};
}